<template>
  <el-config-provider :locale="locale" :size="size">
    <!-- 开启水印 -->
    <el-watermark v-if="watermarkEnabled" :font="{ color: fontColor }" :content="defaultSettings.watermarkContent"
      :z-index="9999" class="wh-full">
      <router-view />
    </el-watermark>
    <!-- 关闭水印 -->
    <router-view v-else />
  </el-config-provider>
</template>

<script setup lang="ts">
  import { getRecipeParams, getRecipeBaseData } from '@/api/Recipe.ts'
  import { useAppStore, useSettingsStore } from "@/store";
  import { useUserStoreHook } from "@/store/modules/user";
  import defaultSettings from "@/settings";
  import { ThemeEnum } from "@/enums/ThemeEnum";
  import { SizeEnum } from "@/enums/SizeEnum";

  import dayjs from 'dayjs';
  const appStore = useAppStore();
  const userStore = useUserStoreHook();
  const settingsStore = useSettingsStore();
  const hasToken = localStorage.getItem("pinia_token") || userStore.pinia_token;
  const locale = computed(() => appStore.locale);
  const size = computed(() => appStore.size as SizeEnum);
  const watermarkEnabled = computed(() => settingsStore.watermarkEnabled);

  // 明亮/暗黑主题水印字体颜色适配
  const fontColor = computed(() => {
    return settingsStore.theme === ThemeEnum.DARK
      ? "rgba(255, 255, 255, .15)"
      : "rgba(0, 0, 0, .15)";
  });
  //查询周开始日期
  const getRecipeParamsApi = async () => {
    let res = await getRecipeParams({})
    if (res.code == 2000) {
      dayjs.en.weekStart = res.data.beginWeek
      // settingsStore.changeBeginWeek(res.data.beginWeek)
    }
  }

  onMounted(() => {


    if (hasToken) {
      getRecipeParamsApi()

    }
  })
</script>
